package com.black.common.mybatis.datascope;

import com.black.common.annotation.DataScope;
import com.black.common.feign.PlatformFeignClient;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author linwenfeng
 */
public abstract class AbstractDataScopeSqlHandler implements DataScopeSqlHandler {

    @Resource
    public PlatformFeignClient platformFeignClient;

    @Value("${share.systemCode:''}")
    public String systemCode;

    @Override
    public List<String> getDataPowerCode(DataScope dataScope) {
        Set<String> result = platformFeignClient.getAllDataPermissionsByUser(systemCode).getResult();
        if (result != null && result.size() > 0) {
            return result.stream().filter(item -> item.contains(dataScope.scopeType())).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }
}
